package com.mall.web.controller.goods.admin;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.mall.goods.model.dto.GoodsCarouselDto;
import com.mall.goods.model.vo.GoodsCarouselVo;
import com.mall.goods.service.IGoodsCarouselService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mall.common.annotation.Log;
import com.mall.common.core.controller.BaseController;
import com.mall.common.core.domain.AjaxResult;
import com.mall.common.enums.BusinessType;
import com.mall.common.utils.poi.ExcelUtil;
import com.mall.common.core.page.TableDataInfo;

/**
 * 商品轮播配置Controller
 *
 * @author mall
 * @date 2024-01-05
 */
@RestController
@RequestMapping("/admin/goods/carousel")
public class AdminGoodsCarouselController extends BaseController
{
    @Autowired
    private IGoodsCarouselService goodsCarouselService;

    /**
     * 查询商品轮播配置列表
     */
    @PreAuthorize("@ss.hasPermi('goods:carousel:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsCarouselDto goodsCarouselDto)
    {
        startPage();
        List<GoodsCarouselVo> list = goodsCarouselService.selectGoodsCarouselList(goodsCarouselDto);
        return getDataTable(list);
    }

    /**
     * 导出商品轮播配置列表
     */
    @PreAuthorize("@ss.hasPermi('goods:carousel:export')")
    @Log(title = "商品轮播配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsCarouselDto goodsCarouselDto)
    {
        List<GoodsCarouselVo> list = goodsCarouselService.selectGoodsCarouselList(goodsCarouselDto);
        ExcelUtil<GoodsCarouselVo> util = new ExcelUtil<GoodsCarouselVo>(GoodsCarouselVo.class);
        util.exportExcel(response, list, "商品轮播配置数据");
    }

    /**
     * 获取商品轮播配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('goods:carousel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(goodsCarouselService.selectGoodsCarouselById(id));
    }

    /**
     * 新增商品轮播配置
     */
    @PreAuthorize("@ss.hasPermi('goods:carousel:add')")
    @Log(title = "商品轮播配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsCarouselDto goodsCarouselDto)
    {
        return toAjax(goodsCarouselService.insertGoodsCarousel(goodsCarouselDto));
    }

    /**
     * 修改商品轮播配置
     */
    @PreAuthorize("@ss.hasPermi('goods:carousel:edit')")
    @Log(title = "商品轮播配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsCarouselDto goodsCarouselDto)
    {
        return toAjax(goodsCarouselService.updateGoodsCarousel(goodsCarouselDto));
    }

    /**
     * 删除商品轮播配置
     */
    @PreAuthorize("@ss.hasPermi('goods:carousel:remove')")
    @Log(title = "商品轮播配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(goodsCarouselService.deleteGoodsCarouselByIds(ids));
    }
}
